Physical Data Services from Java Functions Overview
This page last changed on Nov 28, 2008.
Oracle Data Service Integrator Documentation > Data Services Developer's Guide Physical Data Services from Java Functions OverviewIn Oracle Data Service Integrator, you can create physical data services based on user-defined functions implemented as Java classes. Oracle Data Service Integrator supports Java functions returning the following types:
Oracle Data Service Integrator packages operations marked as create, update, or delete functions in an Entity data service. Otherwise, the resulting data service is of type Library. Functions determined to return void are automatically marked as library procedures. When creating a new physical data service, you can change the nominated function type. The Java method name, when used in an XQuery, becomes the XQuery function name qualified with a namespace.
Simple Java Types and Their XQuery CounterpartsThe following outlines the mapping between simple Java types and the corresponding XQuery or schema types:
Java functions can consume parameters and return values of the following types:
Physical Data Service from a Java Function - Example CodeThis topic provides examples showing the use of imported Java functions in an XQuery and the processing of complex types. Using a Function Returning an Array of Java PrimitivesAs an example, the Java function getRunningTotal can be defined as follows: public static float[] getRunningTotal(float[] list) { if (null == list || 1 >= list.length) return list; for (int i = 1; i < list.length; i++) { list[i] = list[i-1] + list[i]; } return list; } The corresponding XQuery for executing the above function is as follows: Declare namespace f1="ld:javaFunc/float"
Let $y := (2.0, 4.0, 6.0, 8.0, 10.0)
Let $x := f1:getRunningTotal($y)
Return $x
The results of the query is as follows: 2.0, 6.0, 12.0, 20.0, 30.0 Processing complex types represented via XMLBeansConsider a schema called Customer (customer.xsd), as shown in the following: <?xml version="1.0" encoding="UTF-8" ?> <xs:schema targetNamespace="ld:xml/cust:/BEA_BB10000" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="CUSTOMER"> <xs:complexType> <xs:sequence> <xs:element name="FIRST_NAME" type="xs:string" minOccurs="1"/> <xs:element name="LAST_NAME" type="xs:string" minOccurs="1"/> </xs:sequence> </xs:complexType> </xs:element> </xs:schema> You could compile the schema using XMLBeans to generate a Java class corresponding to the types in the schema. xml.cust.beaBB10000.CUSTOMERDocument.CUSTOMER
Following this, you can use the CUSTOMER element as shown in the following: public static xml.cust.beaBB10000.CUSTOMERDocument.CUSTOMER[] getCustomerListGivenCustomerList(xml.cust.beaBB10000.CUSTOMERDocument.CUSTOMER[] ipListOfCust) throws XmlException { xml.cust.beaBB10000.CUSTOMERDocument.CUSTOMER [] mylocalver = pListOfCust; return mylocalver; } The resulting metadata information produced by the New Physical Data Service wizard will be: (::pragma function <f:function xmlns:f="urn:annotations.ld.oracle.com" kind="datasource" access="public"> <params> <param nativeType="[Lxml.cust.beaBB10000.CUSTOMERDocument$CUSTOMER;"/> </params> </f:function>::) declare function f1:getCustomerListGivenCustomerList($x1 as element(t1:CUSTOMER)*) as element(t1:CUSTOMER)* external; The corresponding XQuery for executing the above function is: declare namespace f1 = "ld:javaFunc/CUSTOMER"; let $z := ( validate(<n:CUSTOMER xmlns:n="ld:xml/cust:/BEA_BB10000"><FIRST_NAME>John2</FIRST_NAME><LAST_NAME>Smith2</LAST_NAME> </n:CUSTOMER>), validate(<n:CUSTOMER xmlns:n="ld:xml/cust:/BEA_BB10000"><FIRST_NAME>John2</FIRST_NAME><LAST_NAME>Smith2</LAST_NAME> </n:CUSTOMER>), validate(<n:CUSTOMER xmlns:n="ld:xml/cust:/BEA_BB10000"><FIRST_NAME>John2</FIRST_NAME><LAST_NAME>Smith2</LAST_NAME> </n:CUSTOMER>), validate(<n:CUSTOMER xmlns:n="ld:xml/cust:/BEA_BB10000"><FIRST_NAME>John2</FIRST_NAME><LAST_NAME>Smith2</LAST_NAME> </n:CUSTOMER>)) for $zz in $z return See AlsoHow Tos |
![]() |
Document generated by Confluence on Jan 13, 2009 15:57 |